﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using Framework.Mvc.Attributes;
using OnlineMealOrdering.Domain;
using OnlineMealOrdering.Extends.MvcPager;

namespace OnlineMealOrdering.Areas.WebSiteManage.Models
{
    public class StoreOnlineModel : ModelBase
    {
        [DisplayName("编号")]
        public int Id { get; set; }

        [DisplayName("名称")]
        public string Name { get; set; }

        [DataTablesVisible(false)]
        public string PinYin { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("描述")]
        public string Description { get; set; }

        [DisplayName("电话")]
        public string Tel { get; set; }

        [DisplayName("手机")]
        public string Phone { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("QQ")]
        public string QQ { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("微博")]
        public string WeiBo { get; set; }

        [DisplayName("公告")]
        public string Contact { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("开始营业时间")]
        public DateTime BeginBusinessTime { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("结束营业时间")]
        public DateTime EndBusinessTime { get; set; }

        [DataTablesVisible(false)]
        public decimal Longitude { get; set; }

        [DataTablesVisible(false)]
        public decimal Latitude { get; set; }

        [DataTablesVisible(false)]
        public string LongLati
        {
            get
            {
                return string.Format("{0},{1}", Longitude, Latitude);
            }
            set
            {
                var sp = value.Split(',');
                if (sp.Length > 0)
                {
                    Longitude = Convert.ToDecimal(sp[0]);
                    Latitude = Convert.ToDecimal(sp[1]);
                }
            }
        }

        [DataTablesVisible(false)]
        public List<AreaCoordinateModel> AreaCoordinate { get; set; }

        //电话订餐还是网上订单
        [DisplayName("订餐类型")]
        public string StrType { get; set; }

        //起步价
        [DisplayName("起步价")]
        public decimal InitiatePrice { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("地址")]
        public string Address { get; set; }

        [DisplayName("排序编号")]
        public int SortNo { get; set; }

        [DisplayName("店铺状态")]
        public string StrStatus { get; set; }

        [DataTablesVisible(false)]
        [DisplayName("店铺Logo")]
        public ImageModel LogoImage { get; set; }

        [DataTablesVisible(false)]
        public List<ImageModel> Images { get; set; }


        //推荐或者热销标志
        [DataTablesVisible(false)]
        public List<MarkModel> Marks { get; set; }

        [DataTablesVisible(false)]
        public List<TagModel> Tags { get; set; }


        public static PagedList<StoreOnlineModel> GetAllStoreOnline(int pagindex = 1, int pagsize = 10)
        {
            var query = Ctx.EntitySet<StoreOnlineEntity>().OrderBy(a => a.SortNo);
            var model = query.ToPagedList(a => a.ToStoreOnlineModel(), pagindex, pagsize);
            return model;
        }

        public static StoreOnlineModel GetStoreOnline(int id)
        {
            var entity = StoreOnlineEntity.GetStoreOnline(id);
            return entity.ToStoreOnlineModel();

        }
    }
}